/*
 * =====================================================================================
 *
 *       Filename:  Demultiplexer.h
 *
 *    Description:  wrap select poll epoll 
 * 					class Demultiplexer is a base class
 * 					class Select/Epoll implement the interface

 *        Version:  1.0
 *        Created:  07/13/2012 03:04:39 PM
 *       Revision:  none
 *       Compiler:  gcc/g++
 *
 *         Author:  wangtengchao , wangtengchao AT gmail.com
 *   Organization:  
 *
 * =====================================================================================
 */
#ifndef DEMULTIPLEXER_H
#define DEMULTIPLEXER_H
//#include "defines.h"
#include"eventHandler.h"
#include<boost/noncopyable.hpp>
namespace inm
{
    namespace net
    {
    //register and remove handler should be realized in concre Demultiplexer(not in Dispatcher)
    //because different demultiplexer have different register method

		static const int initTimeout = 100;
        class Demultiplexer : boost::noncopyable
        {//the base class of poll ,epoll,/dev/poll , kqueue
        public:
            virtual void handleEvents(int timeout = initTimeout) = 0;
            virtual void registerEvent(int fd,const short& et)= 0;
            virtual void updateEvent(int fd,const short& et) = 0;
            virtual void removeEvent(int fd, const short& et)= 0;
            void quit() ;
            virtual ~Demultiplexer(){}
            bool isRunning()
            {
                return isRunning_;
            }
            void closeEventHandles()
            {// called by quit
                isRunning_ = false;
            }
            void setDispatcher(Dispatcher* dispatcher)
            {
                dispatcher_ = dispatcher;
            }

        protected:
            Dispatcher* dispatcher_;
			bool isRunning_;
            Demultiplexer(){}

        };
    };
};

#endif
